//
//  FileInfo.m
//  gdemm
//
//  Created by 乔明超 on 16/4/29.
//  Copyright © 2016年 Goldencis. All rights reserved.
//

#import "FileInfo.h"
#import "HttpUtil.h"
#import "InboxManager.h"
#import "FileUtil.h"
#import "NativeEncrypt.h"
#import "ToastManager.h"
@implementation FileInfo
- (instancetype)initWithDictionary:(NSDictionary *)dict{
    
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dict];
        //[self updateState];
    }
    return self;
}

+ (instancetype)fileSyncWithDictionary:(NSDictionary *)dict{
    
    return [[self alloc]initWithDictionary:dict];
    
}

+ (NSArray *)fileSyncWithArray:(NSArray *)array{
    
    NSMutableArray *arr = [NSMutableArray array];
    for (NSDictionary *dict in array) {
        [arr addObject:[self fileSyncWithDictionary:dict]];
    }
    
    return arr;
}

- (BOOL)download{
    if (self.downloading) {
        return NO;
    }
    self.downloading = YES;
    BOOL ret = [HttpUtil downloadTofileWithUrl:self.downloadUrl withFileName:self.localPath];
    self.downloading = NO;
    return ret;
    
}

- (void)updateState{
    NSString *localPath = [NSString stringWithFormat:@"%@/%@",[[InboxManager getInstance]getLocalFilePath:YES],self.fileName];
     self.localPath = localPath;
    
    if ([FileUtil isFileExistWithFilePath:localPath]) {
        self.localExist = YES;
        self.encrypted = [NativeEncrypt isEncryptedFile:self.localPath];
    }else{
    
        self.localExist = NO;
    }
}


@end
